
using System;
using System.Web.UI.Design;
namespace Controls.Designer
{
    /// <summary>
    /// Provides a component editor for the <see cref="SequenceItemCollection"/> collection of <see cref="SequenceSplitter"/> controls. 
    /// </summary>
    public class SequenceSplitsEditor : CollectionEditorBase
    {
        /// <summary>
        /// Avaliable types of <see cref="SequenceItem"/>.
        /// </summary>
        private static readonly Type[] SplitTypes = new Type[] { typeof(AsyncSplitItem), typeof(SplitItem) };

        /// <summary>
        /// Creates an instance of <see cref="SequenceSplitsEditor"/>.
        /// </summary>
        /// <param name="type">Derived type of <see cref="SequenceItem"/>.</param>
        public SequenceSplitsEditor(Type type)
            : base(type)
        {
        }

        /// <summary>
        /// Overriden to return false.
        /// </summary>
        protected override bool CanSelectMultipleInstances()
        {
            return false;
        }

        /// <summary>
        /// Overriden to provide <see cref="SequenceItem"/> type.
        /// </summary>
        /// <returns></returns>
        protected override Type CreateCollectionItemType()
        {
            try
            {
                return typeof(SequenceItem);
            }
            catch(Exception exception)
            {
                throw new ArgumentNullException("value", exception);
            }
        }

        /// <summary>
        /// Overriden to provide <see cref="SequenceItem"/>'s derived types as
        /// available new types.
        /// </summary>
        protected override Type[] CreateNewItemTypes()
        {
            return SplitTypes;
        }
    }
}